/**
 * @module media/media/converters
 */
//import first from '@ckeditor/ckeditor5-utils/src/first';


export function viewToModelAttribute() {
    return dispatcher => {
        console.log('----', dispatcher, '-----')
        dispatcher.on('element', (evt, data, conversionApi) => {
            const viewItem = data.viewItem;


            /*dispatcher.attributeToAttribute({
                model: 'data-path',
                view: {
                    name: viewItem.name,
                    key: 'data-path'
                }
            });*/

            console.log('==', viewItem.name, '==')

            return;


        });
    };
}

/**
 * Converts model to view attributes
 *
 * @param {String} key
 *
 * @returns {Function}
 */
export function modelToViewAttribute(key, schema) {
    return dispatcher => {
        dispatcher.on(`attribute:${key}:${schema}`, (evt, data, conversionApi) => {
            if (!conversionApi.consumable.consume(data.item, evt.name)) {
                return;
            }

            const writer = conversionApi.writer;
            const figure = conversionApi.mapper.toViewElement(data.item);

            //console.log(key,schema,data,figure);

            const element = figure.getChild(0);

            //const attributeKey = stringCamelToLine(data.attributeKey);

            if (data.attributeNewValue !== null) {
                writer.setAttribute(data.attributeKey, data.attributeNewValue, element);
            } else {
                writer.removeAttribute(data.attributeKey, element);
            }
        });
    }
}
